import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.GregorianCalendar;

public class Test {
    public static void callMember(){
        Class<?> c3 = null;
        try {
            c3 = Class.forName("Student");
            Student student = (Student) c3.newInstance();
            student.age = 188;
            System.out.println(student);
            Field field = c3.getDeclaredField("name");
            field.setAccessible(true);
            field.set(student,"mika");
            System.out.println(student);
            Constructor<?> constructor = c3.getDeclaredConstructor(String.class,int.class);
            constructor.setAccessible(true);
            Student student1 = (Student) constructor.newInstance("haha",15);
            System.out.println(student1);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }
    }
    public static void callMethod(){
        Class<?> c3 = null;
        try {
            c3 = Class.forName("Student");
            Student student = (Student)c3.newInstance();
            Method method = c3.getDeclaredMethod("eat");
            method.invoke(student);
            Method method1 = c3.getDeclaredMethod("sleep", String.class);
            method1.setAccessible(true);
            method1.invoke(student,"小猪");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }
    public static void main(String[] args) {
        callMember();
        callMethod();
    }
    public static void main1(String[] args) {
        Student student1 = new Student();
        Class<?> c1 = student1.getClass();

        Class<?> c2 = Student.class;

        Class<?> c3 = null;
        try {
            c3 = Class.forName("Student");
            Student student = (Student) c3.newInstance();
            System.out.println(student);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}
